// abilityType: 0-Ability; 1-Internal Ability
const ABILITY_TYPE_EXTERNAL = 0;
const ABILITY_TYPE_INTERNAL = 1;
// syncOption(Optional, default sync): 0-Sync; 1-Async
const ACTION_SYNC = 0;
const ACTION_ASYNC = 1;
const ACTION_MESSAGE_CODE_PLUS = 1001;
import prompt from '@system.prompt'
export default {
    data: {
        loadStatus:true,
        progressWidth:0,
        list:[
            {
                title: "平",
                progressPercent:30,
            },
            {
                title: "电",
                progressPercent:30,
            },
            {
                title: "手",
                progressPercent:30,
            }
        ]
    },
    plus: async function() {
        var actionData = {};
        actionData.firstNum = 1024;
        actionData.secondNum = 2048;

        var action = {};
        action.bundleName = 'com.wlb.remotectrljs6';
        action.abilityName = 'com.wlb.remotectrljs6.ComputeServiceAbility';
        action.messageCode = ACTION_MESSAGE_CODE_PLUS;
        action.data = actionData;
        action.abilityType = ABILITY_TYPE_EXTERNAL;
        action.syncOption = ACTION_ASYNC;
        this.showToast('00000');

        var result = await FeatureAbility.callAbility(action);
        console.info(result)
        this.showToast(result);
        var ret = JSON.parse(result);
        if (ret.code == 0) {
            console.info('plus result is:' + JSON.stringify(ret.abilityResult));
        } else {
            console.error('plus error code:' + JSON.stringify(ret.code));
        }
    },
    showToast: function (msg) {
        prompt.showToast({
            message: msg
        });
    },
    onInit() {

        this.title = this.$t('strings.world');

    },
    onShow(){
        console.error('plus+++++++++++++++++')
        this.plus().then((res)=>{
            console.log(res)
        });
        if (this.loadStatus) {
            var rect = this.$element('myProgress0').getBoundingClientRect();
            this.progressWidth = rect.width;
            console.log("width:"+rect.width);
            console.log("height:"+rect.height);
            console.log("left:"+rect.left);
            console.log("top:"+rect.top);
        }

    },
    setPercent($idx,e){
        console.log($idx)
        console.log(e)
        let currentProgressPercent = Math.round(e.touches[0].localX/this.progressWidth*100);
        if (currentProgressPercent > 100) {
            this.list[$idx].progressPercent = 100;
        } else if (currentProgressPercent < 0) {
            this.list[$idx].progressPercent = 0;
        } else {
            this.list[$idx].progressPercent = currentProgressPercent;
        }
        console.log($idx)
        console.log(this.list[$idx].progressPercent)
    }
}
